package com.relsell.view.phone;

import java.util.ArrayList;
import java.util.List;

import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.text.Html;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.relsell.controller.CustomListViewAdapter;
import com.relsell.model.RowItem;
import com.relsell.tmcprototype.R;

public class UpcomingLessonsTabs extends Fragment implements OnItemClickListener{
	
	public static final int GOT_DATA_FOR_RECENT_BASS_LESSON = 1001;
	

	public static final String[] titles = new String[] { "Name1", "Name2",
			"Name3", "Name4" };

	public static final String[] descriptions = new String[] { "description1",
			"description2", "description3", "description4" };

	public static final Integer[] images = { R.drawable.ic_launcher,
			R.drawable.ic_launcher, R.drawable.ic_launcher,
			R.drawable.ic_launcher };

	ListView listView;
	List<RowItem> rowItems;

	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View v = inflater.inflate(R.layout.recent_bass_lessons, container,
				false);
		
		setupActionBar();
		
		rowItems = new ArrayList<RowItem>();

		for (int i = 0; i < titles.length; i++) {
			RowItem item = new RowItem(images[i], titles[i], descriptions[i]);
			rowItems.add(item);
		}

		listView = (ListView) v.findViewById(R.id.list);
		CustomListViewAdapter adapter = new CustomListViewAdapter(getActivity(),
				R.layout.list_item, rowItems);
		listView.setAdapter(adapter);
		listView.setOnItemClickListener(this);
		return v;

	}
	
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		Toast toast = Toast.makeText(getActivity(), "Item "
				+ (position + 1) + ": " + rowItems.get(position),
				Toast.LENGTH_SHORT);
		toast.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
		toast.show();
	}

	private void setupActionBar() {
		ActionBar actionBar = getActivity().getActionBar();
		actionBar.setDisplayShowTitleEnabled(false);
		actionBar.setDisplayUseLogoEnabled(false);
		actionBar.setDisplayHomeAsUpEnabled(false);
		actionBar.setDisplayShowCustomEnabled(true);
		actionBar.setDisplayShowHomeEnabled(true);

		View customNav = LayoutInflater.from(getActivity()).inflate(
				R.layout.cutomizedactionbar, null); // layout which contains
													// your button.
		TextView tv = (TextView) customNav.findViewById(R.id.textView1);
		tv.setText(Html.fromHtml(getString(R.string.actionbar_name)));
		actionBar.setCustomView(customNav);
	}
	
	
	

}
